package com.googlecode.monitoring.web.model;

import com.googlecode.monitoring.model.Person;


public class PersonWithId extends Person implements Comparable <PersonWithId>{
	private Integer id;

	public PersonWithId(String fname, String sname, String email, Integer id) {
		super(fname, sname, email);
		this.id = id;
	}

	public PersonWithId(Person person, Integer id) {
		super(person.getFname(), person.getSname(), person.getEmail());
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (!(o instanceof PersonWithId)) {
			return false;
		}
		if (!super.equals(o)) {
			return false;
		}

		PersonWithId that = (PersonWithId) o;

		if (id != null ? !id.equals(that.id) : that.id != null) {
			return false;
		}

		return true;
	}

	@Override
	public int hashCode() {
		int result = super.hashCode();
		result = 31 * result + (id != null ? id.hashCode() : 0);
		return result;
	}

	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();
		sb.append("PersonWithId{");
		sb.append("id='").append(getId()).append('\'');
		sb.append(", fname='").append(getFname()).append('\'');
		sb.append(", sname='").append(getSname()).append('\'');
		sb.append(", email='").append(getEmail()).append('\'');
		sb.append('}');
		return sb.toString();
	}

	@Override
	public int compareTo(PersonWithId o) {
		return this.getId().compareTo(o.getId());
	}
}
